<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-row>
        <el-col :span="6">
          <span>【题型】:{{ questionType[teamList.questionType] }}</span>
        </el-col>
        <el-col :span="6">
          <span>【编号】:{{ teamList.id }}</span>
        </el-col>
        <el-col :span="6">
          <span>【难度】:{{ difficulty[teamList.difficulty] }}</span>
        </el-col>
        <el-col :span="6">
          <span>【标签】:{{ teamList.tags }}</span>
        </el-col>
      </el-row>
      <div class="subject">
        <el-row>
          <el-col :span="6">
            <span>【学科】:{{ teamList.subject }}</span>
          </el-col>
          <el-col :span="6">
            <span>【目录】:{{ teamList.catalog }}</span>
          </el-col>
          <el-col :span="6">
            <span>【方向】:{{ teamList.direction }}</span>
          </el-col>
        </el-row>
        <el-divider></el-divider>
      </div>

      <!-- 单选题 -->
      <div v-if="teamBranch.questionType === '1'">
        <el-row>
          <el-col :span="24">
            <span
              >【题干】:
              <div v-html="teamBranch.question" class="team-color"></div>
              <div class="team">单选题 选项：（以下选中的选项为正确答案）</div>
              <el-col :span="6">
                <el-radio
                  :value="isRight"
                  :label="item.isRight"
                  class="el-radio"
                  v-for="item in teamBranch.options"
                  :key="item.id"
                  >{{ item.title }}
                </el-radio>
              </el-col>
            </span>
          </el-col>
        </el-row>
        <el-divider></el-divider>
      </div>
      <!-- 多选题 -->
      <div v-if="teamBranch.questionType === '2'">
        <el-row>
          <el-col :span="6">
            <span
              >【题干】:
              <div v-html="teamBranch.question" class="team-color"></div>
              <div class="team">多选题选项:（以下选中的选项为正确答案）</div>
              <el-col :span="6">
                <el-checkbox-group  :value="checkList">
                  <el-checkbox
                    :label="item.isRight"
                    :checked="Boolean(item.isRight)"
                    class="el-checkbox"
                    v-for="item in teamBranch.options"
                    :key="item.id"
                    >{{ item.title }}
                  </el-checkbox>
                </el-checkbox-group>
              </el-col>
            </span>
          </el-col>
        </el-row>
        <el-divider></el-divider>
      </div>

      <!-- 简答题 -->
      <div v-if="teamBranch.questionType === '3'">
        <el-row>
          <el-col :span="12">
            <span
              >【题干】:
              <div v-html="teamBranch.question" class="team-color"></div>
              <div class="team">简答题</div>
            </span>
          </el-col>
        </el-row>
        <el-divider></el-divider>
      </div>

      <!-- 参考答案 -->
      <div>
        <el-row>
          <el-col :span="6">
            <span
              >【参考答案】:
              <el-button type="danger" @click="answerFn"
                >视频答案解析</el-button
              ></span
            >
            <!-- 视频标签 -->
            <!-- <video src=""></video> -->
            <div class="demo" v-if="videoShow">
              <video-player
                v-if="videoShow"
                class="video-player vjs-custom-skin"
                ref="videoPlayer"
                :playsinline="true"
                :options="playerOptions"
              >
              </video-player>
            </div>
          </el-col>
        </el-row>
        <el-divider></el-divider>
      </div>

      <!-- 答案解析 -->
      <div>
        <el-row>
          <el-col
            ><span
              >【答案解析】:<span v-html="teamBranch.answer" class="answer">
              </span
            ></span>
          </el-col>
        </el-row>
      </div>
      <el-divider></el-divider>
      <!-- 题目备注 -->
      <div>
        <el-col>
          <span>【题目备注】:{{ teamBranch.remarks }}</span>
        </el-col>
      </div>
      <div class="close">
        <el-button type="primary" @click="closeFn">关闭</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import { choice, detail } from '@/api/hmmm/questions.js'
import 'video.js/dist/video-js.css'
import { videoPlayer } from 'vue-video-player'
export default {
  components: {
    videoPlayer
  },
  name: 'teamView',
  props: {
    // 父组件传过来的id
    userId: {
      type: [Object, Array, String, Number],
      required: true
    }
  },

  data () {
    return {
      checkList: [1], // 多选题组
      playerOptions: {
        playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度
        autoplay: false, // 如果为true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 是否视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
          {
            type: 'video/mp4', // 类型
            src: '' // url地址
          }
        ],
        poster: '', // 封面地址
        notSupportedMessage: '此视频暂无法播放，请稍后再试', // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: true, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: false, // 是否显示剩余时间功能
          fullscreenToggle: true // 是否显示全屏按钮
        }
      },
      videoShow: false, // 视频状态
      teamBranch: [],
      isRight: 1,
      teamList: {},
      form: {},
      questionType: {
        // 试题类型
        1: '单选',
        2: '多选',
        3: '简答'
      },
      difficulty: {
        1: '简单',
        2: '一般',
        3: '困难'
      }
    }
  },
  created () {
    console.log(this.userId)
    this.textListFn() // 调用基础题库列表
    this.detailFn()
  },
  methods: {
    // 答案视频播放按钮
    answerFn () {
      this.playerOptions.sources[0].src = this.teamBranch.videoURL
      this.videoShow = true
    },
    // 关闭弹窗
    closeFn () {
      this.$emit('close')
    },
    // 基础题库列表
    async textListFn () {
      const res = await choice(this.userId)
      //   console.log(res)
      this.teamList = res.data.items[0]
    },
    // 题干
    async detailFn () {
      //   console.log(this.userId)
      const res = await detail({ id: this.userId })
      console.log(res)
      this.teamBranch = res.data // 题目选项
    }
  }
}
</script>

<style>
.demo {
  margin-top: 20px;
}
.video-player vjs-custom-skin {
  width: 350px;
  height: 240px;
}
.el-radio {
  display: block;
  margin-top: 20px;
}
.el-checkbox {
  margin: 15px 0;
}
.team-color {
  color: blue;
}
.team {
  margin-top: 10px;
  margin-bottom: 10px;
}
.subject {
  margin-top: 25px;
  margin-bottom: 10px;
}
.close {
  margin-top: 60px;
  text-align: right;
}
.answer {
  display: inline-block;
}
</style>
